package com.sasken.general.controllers.remoting
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.registerClassAlias;
	
	import mx.collections.ArrayCollection;
	import mx.collections.IList;
	import mx.core.Application;
	import mx.managers.PopUpManager;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	/**
	 *  This class handles data remoting with the server. All classes handle their data requests through this class.
	 *  Only a single instance of this class can be created, it is a singleton. The constructor is not to be used 
	 *  by an implementor. Instead, the get instance() method is to be utilized.
	 * 
	 * <p>The internal workings of the DataModelRemoting object fetch data from the server through a BlazeDS connection.
	 * However, to the users of this class, this is completely hidden.</p>
	 */  
	[Bindable] 
	public class DataRemoting extends EventDispatcher
	{

		public static var ASYNC_TOKEN_INSERT:String = "asyncTokenInsert";
		public static var ASYNC_TOKEN_DELETE:String = "asyncTokenDelete";
		public static var ASYNC_TOKEN_UPDATE:String = "asyncTokenUpdate";
		
		// progress bar values are as follows:
		private static var PROGRESSBAR_MIN_VALUE:int = 0;
		private static var PROGRESSBAR_MAX_VALUE:int = 2;
		private static var PROGRESSBAR_STATE_START:int = 0;
		private static var PROGRESSBAR_STATE_RECEIVE_INIT:int = 1;
		private static var PROGRESSBAR_STATE_RECEIVE_END:int = 2;
		
		private static const _instance:DataRemoting = new DataRemoting();
		
		private var remoting:RemoteObject;
				
		/**
		 *  Constructor. Must not be used. Because of language limitations, however, 
		 *  the constructor is public and can be accessed by the user. 
		 *  Instead of creating a new instance, access this class through its get instance() method.
		 * 
		 * <p></p>
		*/
		public function DataRemoting()
		{
									
			/*
			remoting = new RemoteObject("dataserver");
			remoting.addEventListener(FaultEvent.FAULT, faultListener);
			remoting.addEventListener(ResultEvent.RESULT, resultListener);
			*/
		}
		
		private function faultListener(event:FaultEvent):void
		{
			
			
		}
		
		private function resultListener(e:ResultEvent):void
		{
			
		}
		
		/**
		 * Returns an instance of DataModelRemoting class. Must be used instead of creating new object instances.
		 * @return The instance of DataModelRemoting.
		*/
		public static function get instance():DataRemoting
		{
			return _instance;
		}

	}
}